package org.bluedream.core.module.controller.stock;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bluedream.comm.base.BaseController;
import org.bluedream.core.config.advice.RsaSecurityParameter;
import org.bluedream.core.module.entity.stock.SkuStock;
import org.bluedream.core.module.service.goods.GoodsService;
import org.bluedream.core.module.service.stock.SkuStockService;
import org.bluedream.core.utils.configUtil.GoalConfigUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * @ClassName WareHouseStockController
 * @Description TODO
 * @Author foxsand
 * @Data 2021-08-25 16:35
 * @Version
 */
@Controller
@RequestMapping(value = "${adminPath}/skuStock")
public class SkuStockController extends BaseController {
    @Resource
    private SkuStockService skuStockService;

    @Resource
    private GoodsService goodsService;

    @ModelAttribute
    public SkuStock get(String id){
        return skuStockService.getById(id);
    }

    @RequiresPermissions("skuStock:view")
    @RequestMapping(value = {"/list" , ""})
    public String list(SkuStock entity, Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("skuStock" , entity);
        return "module/stock/skuStockList";
    }

    @RequiresPermissions("reports:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage<SkuStock> findPage(@RsaSecurityParameter SkuStock entity){
        return skuStockService.findPage(entity);
    }

    /**
     * 导出excel演示
     * @param request
     * @param resp
     */
    @RequiresPermissions("reports:view")
    @RequestMapping(value = "/fileDownload" , method = RequestMethod.GET)
    public void fileDownload(HttpServletRequest request, HttpServletResponse resp,@RsaSecurityParameter SkuStock entity){
        System.out.println(entity);
        skuStockService.fileDownload(request , resp , entity);
    }

/*    @RequiresPermissions("clsItem:view")
    @RequestMapping("/treeData")
    @ResponseBody
    public List<Map<String , Object>> treeData(@RequestParam(defaultValue="1")String isShowCode , @RequestParam(defaultValue="undefined")String excludeCode){
        return goodsService.treeData(excludeCode , isShowCode);
    }*/
}
